<?php
/**
 * Created by PhpStorm.
 * User: DaibiDaddy
 * Date: 2016/6/3
 * Time: 14:59
 */

namespace App\Setting;

use App\Base\BaseForm;
use App\Base\ViewsInList;

class ProductSetting{

    /*手动获取的配置项*/
    public $catType = "admin";//Options:level snake
    public $entityCnName = "资讯";//模块名称
    public $table = "Product";//数据表名称
    public $editKeys = array('id','user','shop','cat1','cat2','name','cover','subTitle','price','unit','intro','pics','statistic');//后台管理列表中可以直接编辑的字段
    public $perPage = 10;//后台管理列表中可以直接编辑的字段
    public $noDelete = [];//不想允许删除的ID 放在这里面[0]表示全部禁止删除

    /*自动获取的配置项*/
    public $bundleName;
    public $entityName;
    public $SettingPath;
    public $entityPath;
    public $entity;
    public $modelPath;
    public $doctrine;
    public $em;

    public function __construct($doctrine)
    {
        $this->bundleName = "App";
        $this->entityName = str_replace("\\","",str_replace("Setting","",str_replace(__NAMESPACE__,"",__CLASS__)));
        $this->SettingPath = __CLASS__;
        //$this->entityPath = str_replace($this->entityName."Entity",$this->entityName,str_replace("Setting","Entity",__CLASS__));
        $this->entityPath = "App\\Entity\\".$this->entityName;
        $this->entity = new $this->entityPath();
        $this->modelPath = str_replace("Setting","Model",__CLASS__);
        $this->doctrine = $doctrine;
        $this->em = $doctrine->getManager();
    }

    public function listConfig()
    {
        $default = array();
        $default["Product"]["select"] = array('id','user','shop','cat1','cat2','name','cover','subTitle','price','unit','intro','pics','statistic');
        $default["Product"]["search"] = array('id','user','shop','cat1','cat2','name','cover','subTitle','price','unit','intro','pics','statistic');
        $default["Product"]["condition"] = array('id','user','shop','cat1','cat2','name','cover','subTitle','price','unit','intro','pics','statistic');
        $default["Product"]["orderBy"] = array("id"=>"DESC");

        $join = array();
//        $join["ProductCategory"]["on"] = "";
//        $join["ProductCategory"]["select"] = array();
//        $join["ProductCategory"]["search"] = array();
//        $join["ProductCategory"]["condition"] = array();
//        $join["ProductCategory"]["orderBy"] = array();

        return array(
            "default"   => $default,
            "joins"     => $join,
        );
    }

    public function viewConfig()
    {

    }


    public function formConfig()
    {
        $BaseForm = new BaseForm();
        
        $config["user"] = $BaseForm->text("user","user");
        $config["shop"] = $BaseForm->text("shop","shop");
        $config["cat1"] = $BaseForm->text("cat1","cat1");
        $config["cat2"] = $BaseForm->text("cat2","cat2");
        $config["name"] = $BaseForm->text("name","名称");
        $config["cover"] = $BaseForm->pic("cover","cover");
        $config["subTitle"] = $BaseForm->text("subTitle","subtitle");
        $config["price"] = $BaseForm->text("price","价格");
        $config["unit"] = $BaseForm->text("unit","unit");
        $config["intro"] = $BaseForm->textarea("intro","介绍");
        $config["pics"] = $BaseForm->pics("pics","图片");
        $config["statistic"] = $BaseForm->text("statistic","statistic");
        return $config;
    }
}